/*
 * 
*/
function TweetManager(){
	this.tweets = [];
	this.init();
}

TweetManager.t163 = 'http://t.163.com';
TweetManager.actions = ['get-tweets', 'get-user-info'];
TweetManager.kinds = {'home': 'Home', '@me': 'AtMe', 'private': 'Private'};

TM = TweetManager;

TM.prototype = {
	init: function(){
		var xhr = new XMLHttpRequest(), tm = this;
		this.xhr = xhr;

		this.initEvent();
	},
	initEvent: function(){
		var tm = this;
		chrome.extension.onRequest.addListener(function(request, sender, callback){
			tm.processRequest(request, sender, callback)
		});
	},
	processRequest: function(request, sender, callback){
		var i, j;
		for (i = 0, j = this.actions.length; i < j; i++){
			if (request.action === this.actions[i])
				break;
		}
		if (i >= j)
			return;

		if (request.kind in this.kinds){
			this.process = callback;
			this['getTweetsOf' + this.kinds[request.kind]]();
		}
	},
	processHttpRequest: function(xhr){
		if (xhr.readyState != 4 || xhr.status != 200) return;
		response = JSON.parse(xhr.responseText);
		this.process(response);
	},
	getTweetsOfHome: function(){
		var xhr = this.xhr, tm = this;
		xhr.onreadystatechage = function(){
			tm.processHttpRequest(xhr);
		}
		this.xhr.open('GET', TM.t163 + '/statuses/home_timeline', true);
		xhr.send();
	},
	getReplyTweets: function(){
	},
	dummy: null
}

